Skip to content

fix(decorators): guard _get_fn_argnames against empty positional args (closes #2422) - #2430

Open
feiiiiii5 wants to merge 1 commit into
unionai-oss:mainfrom
feiiiiii5:fix-get-fn-argnames
Open

fix(decorators): guard _get_fn_argnames against empty positional args (closes #2422)#2430
feiiiiii5 wants to merge 1 commit into
unionai-oss:mainfrom
feiiiiii5:fix-get-fn-argnames

Conversation

@feiiiiii5

Copy link
Copy Markdown

Root Cause

_get_fn_argnames() in pandera/decorators.py accessed arg_spec_args[0] without checking if the list was empty. Functions with only keyword-only args (def f(*, x)), variadic args (def f(*args)), or keyword-variadic args (def f(**kwargs)) have an empty args list from inspect.getfullargspec, causing IndexError: list index out of range.

Fix

Add an early return when arg_spec_args is empty, before the [0] access:

if not arg_spec_args:
    return arg_spec_args

This is safe because there are no self/cls args to exclude when the positional args list is empty.

Test

Diff scope

2 files changed, +90/-0 lines (5 lines fix + 86 lines tests)

AI Disclosure

AI-assisted debug/initial draft/testing. Root cause from issue #2422 analysis. Tests verified locally. Human review of diff scope and correctness.

…closes unionai-oss#2422)

_get_fn_argnames() accessed arg_spec_args[0] without checking if the
list was empty. Functions with only keyword-only args (def f(*, x)),
variadic args (def f(*args)), or keyword-variadic args (def f(**kwargs))
have an empty args list from inspect.getfullargspec, causing IndexError.

Fix: add an early return when arg_spec_args is empty, before the [0]
access. This is safe because there are no self/cls args to exclude.

Impact: any pandera decorator (@check_input, @check_output, @check_io,
@check_types) applied to a function with only keyword-only parameters
would crash during argument introspection.

Regression tests cover:
- keyword-only args (exact repro from unionai-oss#2422)
- variadic args only (*args)
- kwargs only (**kwargs)
- no args at all
- Normal cases still work (regular function, method excludes self,
  mixed positional + keyword-only)

Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant